
import { _decorator, Component, Node, Slider, Toggle, input, Input, EventKeyboard, KeyCode, assetManager, AudioClip, Label, Button, instantiate, Prefab } from 'cc';
import { mb, mb_base_cp, mb_config, mb_audio } from 'db://magic-book/src';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = NewComponent
 * DateTime = Fri Jun 10 2022 19:43:09 GMT+0800 (中国标准时间)
 * Author = 磨刀石
 * FileBasename = NewComponent.ts
 * FileBasenameNoExtension = NewComponent
 * URL = db://assets/audio/NewComponent.ts
 * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
 *
 */
@ccclass('audio')
export class audio extends Component {

    @property(Label)
    Label: Label = null;

    onLoad() {
        mb_config.is_debug = true;
        mb.init();

        assetManager.resources.loadDir("audio", AudioClip, (err, data: AudioClip[]) => {
            mb_audio.load_res(data);
        });
    }

    private _play(name: string) {
        if (name.indexOf("music") != -1) {
            mb_audio.play_music(name, true);
        } else {
            mb_audio.play_effect(name);
        }
    }

    update() {
        this.Label.string = `music ${mb_audio.cur_audio_music_channel} effect ${mb_audio.cur_audio_effect_channel} / max channel ${mb_audio.max_audio_channel}`;
    }
}
